package com.ruoyi.sl.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.sl.domain.SlColour;
import com.ruoyi.sl.service.ISlColourService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 颜色Controller
 * 
 * @author admin
 * @date 2024-06-03
 */
@RestController
@RequestMapping("/sl/colour")
public class SlColourController extends BaseController
{
    @Autowired
    private ISlColourService slColourService;

    /**
     * 查询颜色列表
     */
    @PreAuthorize("@ss.hasPermi('sl:colour:list')")
    @GetMapping("/list")
    public TableDataInfo list(SlColour slColour)
    {
        startPage();
        List<SlColour> list = slColourService.selectSlColourList(slColour);
        return getDataTable(list);
    }

    /**
     * 获取所有颜色
     */
    @GetMapping(value = "/all")
    public AjaxResult getAllList()
    {
        return success(slColourService.selectColourAll());
    }

    /**
     * 导出颜色列表
     */
    @PreAuthorize("@ss.hasPermi('sl:colour:export')")
    @Log(title = "颜色", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, SlColour slColour)
    {
        List<SlColour> list = slColourService.selectSlColourList(slColour);
        ExcelUtil<SlColour> util = new ExcelUtil<SlColour>(SlColour.class);
        util.exportExcel(response, list, "颜色数据");
    }

    /**
     * 获取颜色详细信息
     */
    @PreAuthorize("@ss.hasPermi('sl:colour:query')")
    @GetMapping(value = "/{colourId}")
    public AjaxResult getInfo(@PathVariable("colourId") Long colourId)
    {
        return success(slColourService.selectSlColourByColourId(colourId));
    }

    /**
     * 新增颜色
     */
    @PreAuthorize("@ss.hasPermi('sl:colour:add')")
    @Log(title = "颜色", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody SlColour slColour)
    {
        slColour.setCreateBy(getUsername());
        return toAjax(slColourService.insertSlColour(slColour));
    }

    /**
     * 修改颜色
     */
    @PreAuthorize("@ss.hasPermi('sl:colour:edit')")
    @Log(title = "颜色", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody SlColour slColour)
    {
        slColour.setUpdateBy(getUsername());
        return toAjax(slColourService.updateSlColour(slColour));
    }

    /**
     * 删除颜色
     */
    @PreAuthorize("@ss.hasPermi('sl:colour:remove')")
    @Log(title = "颜色", businessType = BusinessType.DELETE)
	@DeleteMapping("/{colourIds}")
    public AjaxResult remove(@PathVariable Long[] colourIds)
    {
        return toAjax(slColourService.deleteSlColourByColourIds(colourIds));
    }
}
